//
//  MYOrginalView.swift
//  swift2.0项目开始
//
//  Created by 龚昕炜 on 16/8/1.
//  Copyright © 2016年 龚昕炜. All rights reserved.
//

import UIKit

class MYOrginalView: UIView {

    /** 模型属性 */
    var originalViewModel: MYHomeCellViewModel? {
        
        didSet {
            /** 个人信息 */
            nameLabel.text = originalViewModel?.screen_name
            
            /** 设置头像 */
            photoImageView.sd_setImageWithURL(originalViewModel?.photoURL, placeholderImage: UIImage(named: "avatar_default_big"))
            
            /** 认证图片 */
            verfitiedImageView.image = originalViewModel?.verfited_Image
            
            /** 等级图片 */
            levelImageView.image = originalViewModel?.level_Image
            
            /** 内容 */
            contentLabel.text = originalViewModel?.statusModel?.text
        }
    }
    
    /** 重写构造函数 */
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /** 设置控件 */
    private func setUpUI(){
        
        addSubview(photoImageView)
        addSubview(verfitiedImageView)
        addSubview(nameLabel)
        addSubview(levelImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contentLabel)
        
        let HomeCellMargin = 10.0
        /** 约束 */
        /** 头像 */
        photoImageView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(HomeCellMargin)
            make.top.equalTo(self.snp_top).offset(HomeCellMargin)
            make.height.width.equalTo(50)
        }
        
        /** 认证 */
        verfitiedImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(photoImageView.snp_right)
            make.centerY.equalTo(photoImageView.snp_bottom)
        }
        
        /** 名字 */
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(photoImageView.snp_right).offset(HomeCellMargin)
            make.top.equalTo(photoImageView.snp_top)
        }
        
        /** 等级 */
        levelImageView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLabel.snp_right).offset(HomeCellMargin)
            make.centerY.equalTo(nameLabel.snp_centerY)
        }
        
        /** 时间 */
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(photoImageView.snp_right).offset(HomeCellMargin)
            make.top.equalTo(nameLabel.snp_bottom).offset(HomeCellMargin)
        }
        
        /** 来源 */
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLabel.snp_right).offset(HomeCellMargin)
            make.centerY.equalTo(timeLabel.snp_centerY)
        }
        
        /** 内容 */
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(photoImageView.snp_bottom).offset(HomeCellMargin)
            make.right.equalTo(self.snp_right)
            make.bottom.equalTo(self.snp_bottom)
        }
    }
    
    /** 懒加载控件 */
    /** 头像 */
    private lazy var photoImageView: UIImageView = {
        
        let img = UIImageView()
        
        img.image = UIImage(named: "avatar_default_big")
        
        return img
    }()
    
    /** 认证图片 */
    private lazy var verfitiedImageView: UIImageView = {
    
        let img = UIImageView()
        
        img.image = UIImage(named: "avatar_enterprise_vip")
        
        return img
    }()
    
    /** 名字 */
    private lazy var nameLabel: UILabel = {
    
        let label = UILabel()
        
        label.text = "名字"
        label.font = UIFont.systemFontOfSize(15)
        label.textColor = UIColor.darkGrayColor()
        return label
    }()

    /** 等级 */
    private lazy var levelImageView: UIImageView = {

        let img = UIImageView()

        img.image = UIImage(named: "common_icon_membership_level1")

        return img
    }()

    /** 时间 */
    private lazy var timeLabel: UILabel = {

        let label = UILabel()

        label.text = "时间"
        label.font = UIFont.systemFontOfSize(13)
        label.textColor = UIColor.orangeColor()

        return label
    }()
    
    /** 来源 */
    private lazy var sourceLabel: UILabel = {
        
        let label = UILabel()
        
        label.text = "来源"
        label.font = UIFont.systemFontOfSize(13)
        label.textColor = UIColor.darkGrayColor()
        
        return label
    }()
    
    /** 内容 */
    private lazy var contentLabel: UILabel = {
        
        let label = UILabel()
        
        label.text = "asdasdasasasdasdasassdasdasdasdasdasdasdasdassd"
        label.font = UIFont.systemFontOfSize(16)
        label.textColor = UIColor.blackColor()
        label.numberOfLines = 0
        
        return label
    }()
}
